import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-02-27
 * Time: 18:09
 */
class Card {
    private int rank;//数字
    private String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "[ 花色:"+this.suit+" "+this.rank+" ]";
    }
}
//没有大小王：1，2，3，4，5，6，7，8，9，10，11，12，13
public class TestDemo {
    private static final String[] suits = {"♥","♠","♣","♦"};
    public static List<Card> buyCard() {
        ArrayList<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {/*
                int rank = j;
                String suit = suits[i];
                Card card = new Card(j,suits[i]);
                cards.add(card);*/
                cards.add(new Card(j,suits[i]));
            }
        }
        return cards;
    }
    private static void swap(List<Card> cards,int i,int j) {
//      Card tmp = cards[i];
        Card tmp = cards.get(i);
//      cards[i] = cards[j];
        cards.set(i,cards.get(j));
//      cards[j] = tmp;
        cards.set(j,tmp);
    }
    public static void shuffle(List<Card> cards) {
        int size = cards.size();
        for (int i = size-1; i > 0; i--) {
            Random random = new Random();
            int rand = random.nextInt(i);
            swap(cards,i,rand);
        }
    }
    //扑克牌：
    public static void main(String[] args) {
        List<Card> cards = buyCard();
        System.out.println("买牌："+cards);
        shuffle(cards);
        System.out.println("洗牌："+cards);

        System.out.println("接牌：3个人每个人轮流接5张牌");
        ArrayList<List<Card>> hand = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                hand.get(j).add(card);
            }
        }
        System.out.println("第1个人的牌： "+hand1);
        System.out.println("第2个人的牌： "+hand2);
        System.out.println("第3个人的牌： "+hand3);
        System.out.println("剩下的牌： "+cards);

    }
    public static void main1(String[] args) {
        Card card = new Card(3,"♥");
        System.out.println(card);
    }
}
